package com.pubinfo.passbook.common.entity;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.pubinfo.passbook.common.handler.InvoiceListHandler;
import com.pubinfo.passbook.common.model.bo.contract.TaxInfo;
import com.pubinfo.passbook.common.model.dto.contract.InvoiceData;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 发票凭证
 *
 * @TableName t_contract_invoice_header
 */
@TableName(value = "t_contract_invoice_header")
@Data
public class TContractInvoiceHeader implements Serializable {
  
  @ApiModelProperty("发票流水号")
  @TableId(value = "invoice_id")
  private String invoiceId;
  
  /**
   * 类型
   */
  private Integer type;
  @ApiModelProperty("合同ID")
  @TableField(value = "contract_id")
  private Integer contractId;
  
  @ApiModelProperty("合同编号")
  @TableField(value = "contract_code")
  private String contractCode;
  
  @ApiModelProperty("开票日期")
  @TableField(value = "invoice_date")
    private Date invoiceDate;

    @ApiModelProperty("发票代码")
    @TableField(value = "invoice_code")
    private String invoiceCode;

    @ApiModelProperty("发票号码")
    @TableField(value = "invoice_number")
    private String invoiceNumber;

    @ApiModelProperty("发票号码")
    @TableField(value = "payer_name")
    private String payerName;

    @ApiModelProperty("开票金额(价税合计)")
    @TableField(value = "invoice_amount")
    private BigDecimal invoiceAmount;

    @ApiModelProperty("税率")
    @TableField(value = "tax_rate")
    private BigDecimal taxRate;

    @ApiModelProperty("税金")
    @TableField(value = "tax_amount")
    private BigDecimal taxAmount;

    @ApiModelProperty("不含税金额")
    @TableField(value = "amount")
    private BigDecimal amount;
  
  @ApiModelProperty("创建时间")
  @TableField(fill = FieldFill.INSERT)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date createTime;
  
  @ApiModelProperty("更新时间")
  @TableField(fill = FieldFill.UPDATE)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date updateTime;
  
  @ApiModelProperty("状态")
  @TableField(value = "status")
  private Integer status;
  
  /**
   * 发票类型
   */
  private String invoiceType;
  
  /**
   * 购买方税号
   */
  private String gmfPinTaxId;
  
  /**
   * 购买方名称
   */
  private String gmfPinTaxName;
  
  /**
   * 销售方税号
   */
  private String xsfPinTaxId;
  
  /**
   * 销售方名称
   */
  private String xsfPinTaxName;
  
  /**
   * 发票状态
   */
  private String invoiceState;
  @TableField(typeHandler = InvoiceListHandler.class)
  private List<TaxInfo> taxInfos;
  
  @TableField(exist = false)
  private static final long serialVersionUID = 1L;
  
  public TContractInvoiceHeader(InvoiceData invoiceData) {
    BeanUtils.copyProperties(invoiceData, this);
    taxInfos = invoiceData.getTaxInfo();
    this.invoiceNumber = invoiceData.getInvoiceNo();
    this.invoiceDate = DateUtil.parse(invoiceData.getStateDate(), "yyyy-MM-dd HH:mm:ss");
    
  }
}
